<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    const student = {
      name: "Jay",
      fruits: ["Apple", "Banana"],
      attrs: {
        age: 20,
        nickname: "J",
      },
    };

    function deepClone(obj = {}) {
      if (typeof obj !== "object" || obj == null) {
        return obj;
      }
      let result = {};
      // 初始化返回结果
      if (
        obj instanceof Array ||
        // 加 || 的原因是为了防止 Array 的 prototype 被重写，Array.isArray 也是如此
        Object.prototype.toString(obj) === "[object Array]"
      ) {
        result = [];
      }

      for (let key in obj) {
        if (Object.hasOwnProperty.call(obj, key)) {
          result[key] = deepClone(obj[key]);
        }
      }
      return result;
    }
    const student2 = deepClone(student);
    student2.name = "Michel";
    student2.attrs.age = 21;
    // console.log("1: ", student);
    // console.log("2: ", student2);

    var value = 100;
    function fn() {
      this.value++;
      return this.value;
    }
    var obj = { value: 1, fn };
    function delay(fn, delay) {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve(fn());
        }, delay);
      });
    }

    async function run() {
      var value = 10;
      try {
        const pms1 = delay(fn, 100);
        const pms2 = delay(obj.fn, 200);
        const value1 = await pms1;
        const value2 = await pms2;
        const value3 = await delay(fn.bind(obj), 300);
        console.log('value1: ', value1)
        console.log('value2: ', value2)
        console.log('value3: ', value3)
      } catch (err) {
        console.error(err);
      }
    }
    run(); //问题//value1:// value2:// value3://总耗时:
  </script>
</html>
